<?
/************************************************************************/
/* FlatNuke - Flat Text Based Content Management System                 */
/* ============================================                         */
/*                                                                      */
/* Copyright (c) 2003-2004 by Simone Vellei                             */
/* http://flatnuke.sourceforge.net                                      */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

// Section Features Request Board
// with flatnkuke

//--------------------------------------------------------------------------
// formato file Features
//--------------------------------------------------------------------------
// 0 priority			PRIORITA
// 1 submitted 			$MYFORUM
// 2 name 			NOME DEL COMANDO
// 3 syntax			SINTASSI
// 4 description		DESCRIZIONE DETAGLIATA
// 5 implementation		SUGGERIMENTI DEL SUBMITTER
// 6 codeexample		FRAMMENTO DI CODICE PER IL TEST
// 7 implementationreport 	REPORT DI IMPLEMENTAZIONE
//--------------------------------------------------------------------------


if (eregi("section.php",$_SERVER['PHP_SELF']))
	{ Header("Location: ../../index.php");
	die();
}

// VARIABILI RICEVIBILI
$modname =$_GET['mod'];
$action=$_GET['action'];
$filename=$_GET['filename'];
$dirname=$_GET['dirname'];


include"config.php";
//fissa $siteurl se non finisce con /
if (substr($siteurl,-1)!="/")$siteurl=$siteurl."/";


//carica la lingua se esiste
if (file_exists("sections/$modname/.lang/$lang.php"))
    include "sections/$modname/.lang/$lang.php";
else
    include "sections/$modname/.lang/it.php";


// le directory di lavoro
$featuresdir="misc/features/requested";
$implementeddir="misc/features/implemented";

// genera le cartelle di features se non ci sono in misc
if (!file_exists("misc/features"))mkdir("misc/features");
if (!file_exists("misc/features/requested"))mkdir("misc/features/requested");
if (!file_exists("misc/features/implemented"))mkdir("misc/features/implemented");


if ($action=="")$action="features";


// genera il menu
echo "
    <table>
    <tr>
    <td>	[<b><a href='index.php?mod=$modname&action=submit'>"._SUBMIT_NEW."	</a></b>]</td>
    <td>	[<b><a href='index.php?mod=$modname&action=features'>"._LIST_FEATURES."		</a></b>]</td>
    <td>	[<b><a href='index.php?mod=$modname&action=implemented'>"._LIST_IMPLEMENTED."	</a></b>]</td>
    <td>	[<b><a href='index.php?mod=$modname&action=help'>"._HELP."		</a></b>]</td>
    </tr>
    </table>
    ";
//---------------------------------------------------------------------------------------------------------------------------------------

// action report: il visualizzatore / editore dei bug sottomessi
if ($action=="submit"){

    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/NewFeature.png' border=0></td>\n";
    echo "<td><h1>"._FEATURE_SUBMIT."</h1></td>\n";
    echo "</tr></table>\n";

    // se e' un file nuovo si attribuisce il nome
    if ($filename==""){
	$filename=time();
	$dirname=$featuresdir;
    }

    if (getlevel($_COOKIE['myforum'],"home")<0)
	 echo"<h2>"._WARNING_USER."</h2>\n";

    // se esiste si caricano i valori
    if (file_exists("$dirname/$filename")){
	$f=file("$dirname/$filename");
	$priority=$f[0];
	$submitted=$f[1];
	$name=$f[2];
	$syntax=urldecode(substr($f[3],0,-1));
	$description=urldecode(substr($f[4],0,-1));
	$implementation=urldecode(substr($f[5],0,-1));
	$codeexample=urldecode(substr($f[6],0,-1));
	$implementationreport=urldecode(substr($f[7],0,-1));
	if (((getlevel($_COOKIE['myforum'],"home")!=10) or versecid($_COOKIE['myforum'])) ||( trim($submitted) != trim($_COOKIE['myforum']))){
		echo"<h2>"._WARNING_POST."</h2>\n";
	}
    }
    else{
	$submitted=$_COOKIE['myforum'];
	$priority=0;
	$name="";
	$syntax="";
	$description="";
	$implementation="";
	$codeexample="";
	$implementationreport="";
    }



    echo "
    <hr>\n
    <form name='submit' enctype='multipart/form-data' action='index.php?mod=$modname&action=exec_submit' method='post' >\n
    <table width='100%'>\n

    <input type='hidden' name='filename' value='$filename' />\n
    <input type='hidden' name='dirname' value='$dirname' />\n
    ";

    if((getlevel($_COOKIE['myforum'],"home")==10) and versecid($_COOKIE['myforum'])){
	echo "
	<tr bgcolor='#ffeeee'>\n
	<td><b>"._PRIORITY."</b></td>
	<td><select name='priority' value='$priority'>\n";
	echo"<option>$priority</option>\n";
	for ($i=0;$i<=5;$i++)echo"<option>$i</option>\n";
	echo"</select>\n </td>\n
	</tr>\n
	";
	echo "<tr bgcolor='#eeeeee'>\n";
	echo"<td><b>"._SUBMITTED_BY."</b></td><td><input type=text name='submitted' value='$submitted' /></td>\n
	</tr>\n
	";

    }else{
	echo "
	<input type=hidden name='submitted' value='$submitted' />\n";
    }
    echo "
    <tr bgcolor='#ffffee'>\n
    <td><b>"._FEATURE_NAME."</b></td><td><input type=text name='name' value='$name' size='63' /></td>\n
    </tr>\n
    <tr bgcolor='#ffeeff'>\n
    <td><b>"._FEATURE_SYNTAX."</b></td><td><input type=text name='syntax' value='$syntax' size='63' /></td>\n
    </tr>\n
    <tr bgcolor='#eeffff'>\n
    <td><b>"._DESCRIPTION."</b></td><td><textarea name='description' rows='5' cols='60' >$description</textarea></td>\n
    </tr>\n
    <tr bgcolor='#ffeeee'>\n
    <td><b>"._IMPLEMENTATION."</b></td><td><textarea name='implementation' rows='5' cols='60' >$implementation</textarea></td>\n
    </tr >\n
    <tr bgcolor='#eeeeff'>\n
    <td><b>"._CODE_EXAMPLE."</b></td><td><textarea name='codeexample' rows='5' cols='60' >$codeexample</textarea></td>\n
    </tr >\n
    ";
    if(((getlevel($_COOKIE['myforum'],"home")==10) and versecid($_COOKIE['myforum']))|| $dirname==$implementeddir){
	echo "
	<tr bgcolor='#ddffdd'>\n
	<td><b>"._IMPLEMENTATION_REPORT."</b></td><td><textarea name='implementationreport' rows='5' cols='60' >$implementationreport</textarea></td>\n
	</tr>\n
	";
    }

    echo "
    <tr bgcolor='#ffaaaa'>\n
    <td></td><td><input type='submit' /> <input type='reset' /> </td>\n
    </tr>\n
    </table>\n
    <hr />
    ";

    //amministrazione
    if((getlevel($_COOKIE['myforum'],"home")==10) and versecid($_COOKIE['myforum'])){
    echo "
    <table>
    <tr>
    <td><img src='sections/$modname/.images/Wip.png' border=0></td>\n
    <td><h2> "._FEATURE_ADMIN." </h2></td>
    <td>[<b><a href='index.php?mod=$modname&action=exec_delete&dirname=$dirname&filename=$filename'>"._DELETE."</a></b>]</td> \n
    <td>[<b><a href='index.php?mod=$modname&action=exec_implemented&dirname=$dirname&filename=$filename'>"._IMPLEMENTED."</a></b>]</td> \n
    <td>[<b><a href='index.php?mod=$modname&action=exec_unimplemented&dirname=$dirname&filename=$filename'>"._UNIMPLEMENTED."</a></b>]  </td> \n
    </tr>
    </table>
    ";
    }
    echo "<hr/>\n";
}
//---------------------------------------------------------------------------------------------------------------------------------------


if ($action=="exec_submit"){
    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/notes.png' border=0></td>\n";
    echo "<td><h1>"._SUBMIT."</h1></td>\n";
    echo "</tr></table>\n";

   if(getlevel($_COOKIE['myforum'],"home")>=0 ){
	$myforum=$_COOKIE['myforum'];
	$priority=$_POST['priority'];
	$filename=$_POST['filename'];
	$dirname=$_POST['dirname'];


	$name=$_POST['name'];
	$syntax=$_POST['syntax'];
	$description=urlencode($_POST['description']);
	$implementation=urlencode($_POST['implementation']);
	$codeexample=urlencode($_POST['codeexample']);
	$implementationreport=urlencode($_POST['implementationreport']);


	if(getlevel($_COOKIE['myforum'],"home")==10 ){
	    $submitted=$_POST['submitted'];
	}else{
	    $submitted=$_COOKIE['myforum'];
	}

	if (!file_exists("$dirname/$filename") || getlevel($_COOKIE['myforum'],"home")==10 || trim($submitted) == trim($_COOKIE['myforum']) ){
	    if(getlevel($_COOKIE['myforum'],"home")>=0){

		print "<br/>"._FEATURE_NAME."=$name<br/>\n";
		print "<br/>"._FEATURE_SYNTAX."=$syntax<br/>\n";
		print "<br/>"._DESCRIPTION."=$description<br/>\n";
		print "<br/>"._IMPLEMENTATION."=$implementation<br/>\n";
		print "<br/>"._CODE_EXAMPLE."=$codeexample<br/>\n";
		print "<br/>"._IMPLEMENTATION_REPORT."=$implementationreport<br/>\n";
		print _SUBMITTED_BY." $submitted <br/>\n";

		//*
		$hf=fopen("$dirname/$filename","w");
		fwrite($hf,"$priority\n");
		fwrite($hf,"$submitted\n");
		fwrite($hf,"$name\n");
		fwrite($hf,"$syntax\n");
		fwrite($hf,"$description\n");
		fwrite($hf,"$implementation\n");
		fwrite($hf,"$codeexample\n");
		fwrite($hf,"$implementationreport\n");
		fclose($hf);
		//*/
		echo "<b>"._TANK_YOU."</b><br/>\n";

		echo "<p align='right'>[<a href='index.php?mod=$modname&action=features'>"._CONTINUE."</a>]</p><br/><br/><br/><hr />";
	    }

	    else
		die(_AUTH_ERR);

	}
    }
    else
	die(_NONPUOI);
}
//---------------------------------------------------------------------------------------------------------------------------------------

if ($action=="features"){
    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/NewFeature.png' border=0></td>\n";
    echo "<td><h1>"._LIST_FEATURES."</h1></td>\n";
    echo "</tr></table>\n";

    $filter=$_GET['filter'];

    echo "<b>"._PRIORITY_FILTER."</b> . <select name='filter' onchange=\"javascript:window.location.href='index.php?mod=$modname&action=$action&filter='+value; \" >\n";
    echo"<option>$filter</option>\n";
    echo"<option></option>\n";
    for ($i=0;$i<=5;$i++)echo"<option>$i</option>\n";
    echo"</select>\n <br/>\n";

    echo "<hr/><table border=1>\n";
    echo "
    <tr bgcolor='ff0000' >\n
    <td ><h2> ID </h2></td><td><h2> "._PRIORITY." </h2></td><td><h2> "._FEATURE_NAME." </h2></td><td><h2> "._SUBMITTED_BY." </h2></td><td><h2> "._VIEW." </h2></td>\n
    </tr>\n
    ";

    $hdir=opendir($featuresdir);
    $i=0;
    while (false !== ($fa[$i++]= readdir($hdir)));
    closedir($hdir);
    for($i=0;$i<6;$i++){
	if ($filter != "" )$i=0+$filter;
	foreach($fa as $f ){
	    if (substr($f,0,1)!="." && $f!=""){
		$fl=file("$featuresdir/$f");
		if ($i == $fl[0]){
		    $view="<a href='index.php?mod=$modname&action=submit&dirname=$featuresdir&filename=$f'>"._VIEW."</a>";

		    if($fl[0]==0){echo "<tr bgcolor='#e0e0e0'>\n";$fl[0]=_UNASSIGNED;}
		    if($fl[0]==1)echo "<tr bgcolor='#F06000'>\n";
		    if($fl[0]==2)echo "<tr bgcolor='#F08000'>\n";
		    if($fl[0]==3)echo "<tr bgcolor='#F0A000'>\n";
		    if($fl[0]==4)echo "<tr bgcolor='#F0C000'>\n";
		    if($fl[0]==5)echo "<tr bgcolor='#F0F000'>\n";

		    echo "
		    <td><b> $f </b></td><td><b> ".$fl[0]." </b></td><td><b> ".$fl[2]." </b></td><td><b> ".$fl[1]." </b></td><td><b> $view </b></td>\n
		    </tr>\n
		    ";
		}
	    }
	}
	if ($i." " == $filter." ")break;
    }
    echo "</table >\n";

    echo "<hr/>\n";
}
//---------------------------------------------------------------------------------------------------------------------------------------

if ($action=="implemented"){
    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/NewRelease.png' border=0></td>\n";
    echo "<td><h1>"._LIST_IMPLEMENTED."</h1></td>\n";
    echo "</tr></table>\n";

    $filter=$_GET['filter'];

    echo "<b>"._PRIORITY_FILTER."</b> . <select name='filter' onchange=\"javascript:window.location.href='index.php?mod=$modname&action=$action&filter='+value; \" >\n";
    echo"<option>$filter</option>\n";
    echo"<option></option>\n";
    for ($i=0;$i<=5;$i++)echo"<option>$i</option>\n";
    echo"</select>\n <br/>\n";

    echo "<hr/><table border=1>\n";
    echo "
    <tr bgcolor=\"00ff00\">\n
    <td><h2> ID </h2></td><td><h2> "._PRIORITY." </h2></td><td><h2> "._FEATURE_NAME." </h2></td><td><h2> "._SUBMITTED_BY." </h2></td><td><h2> "._VIEW." </h2></td>\n
    </font>
    </tr>\n
    ";
    $hdir=opendir($implementeddir);
    $i=0;
    while (false !== ($fa[$i++]= readdir($hdir)));
    closedir($hdir);
    for($i=0;$i<6;$i++){
	if ($filter != "" )$i=0+$filter;
	foreach($fa as $f ){
	    if (substr($f,0,1)!="." && $f!=""){
		$fl=file("$implementeddir/$f");
		if ($i==$fl[0]){

	$view="<a href='index.php?mod=$modname&action=submit&dirname=$implementeddir&filename=$f'>"._VIEW."</a>";

		    if($fl[0]==0){echo "<tr bgcolor='#e0e0e0'>\n";$fl[0]=_UNASSIGNED;}
		    if($fl[0]==1)echo "<tr bgcolor='#F06000'>\n";
		    if($fl[0]==2)echo "<tr bgcolor='#F08000'>\n";
		    if($fl[0]==3)echo "<tr bgcolor='#F0A000'>\n";
		    if($fl[0]==4)echo "<tr bgcolor='#F0C000'>\n";
		    if($fl[0]==5)echo "<tr bgcolor='#F0F000'>\n";

		    echo "
		    <td><b> $f </b></td><td><b> ".$fl[0]." </b></td><td><b> ".$fl[2]." </b></td><td><b> ".$fl[1]." </b></td><td><b> $view </b></td>\n
		    </tr>\n
		    ";
		}
	    }
	}
	if ($i." " == $filter." ")break;
    }
    echo "</table >\n";

    echo "<hr/>\n";
}
//---------------------------------------------------------------------------------------------------------------------------------------

if ($action=="exec_delete"){
    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/Out.gif' border=0></td>\n";
    echo "<td><h1>"._REPORT_DELETED."</h1></td>";
    echo "</tr></table><hr>\n";
    $f=file("$dirname/$filename");
    unlink("$dirname/$filename");
    echo "<p align='right'>[<a href='index.php?mod=$modname&action=features'>"._CONTINUE."</a>]</p><br/><br/><br/><hr />";
}
//---------------------------------------------------------------------------------------------------------------------------------------

if ($action=="exec_implemented"){
    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/NewRelease.png' border=0></td>\n";
    echo "<td><h1>"._FEATURE_IMPLEMENTED."</h1></td>\n";
    echo "</tr></table><hr>\n";
    copy("$dirname/$filename","$implementeddir/$filename");
    if ($dirname!=$implementeddir)unlink("$dirname/$filename");
    echo "<p align='right'>[<a href='index.php?mod=$modname&action=features'>"._CONTINUE."</a>]</p><br/><br/><br/><hr />";

}
//---------------------------------------------------------------------------------------------------------------------------------------

if ($action=="exec_unimplemented"){
    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/NewFeature.png' border=0></td>\n";
    echo "<td><h1>"._FEATURE_UNIMPLEMENTED."</h1></td>";
    echo "</tr></table><hr>\n";

    copy("$dirname/$filename","$featuresdir/$filename");
    if ($dirname==$implementeddir)unlink("$dirname/$filename");
    echo "<p align='right'>[<a href='index.php?mod=$modname&action=features'>"._CONTINUE."</a>]</p><br/><br/><br/><hr />";

}
//---------------------------------------------------------------------------------------------------------------------------------------

if ($action=="help"){

    echo "<table><tr>\n";
    echo "<td><img src='sections/$modname/.images/Help.png' border=0></td>\n";
    echo "<td><h2>"._HELP_TITLE."</h2></td>";
    echo "</tr></table>\n";

    echo "<br/>"._HELP_DOC."<br />";
    echo "<p align='right'>[<a href='index.php?mod=$modname&action=features'>"._CONTINUE."</a>]</p><br/><br/><br/><hr />";
}
//---------------------------------------------------------------------------------------------------------------------------------------

?>

